package com.zhanghaijun.createCode.service;

import com.zhanghaijun.createCode.bean.EnumUnit;
import com.zhanghaijun.createCode.util.Constant;
import com.zhanghaijun.createCode.util.TableNameConvertUtil;
import freemarker.core.Environment;
import freemarker.template.Configuration;
import freemarker.template.Template;

import java.io.File;
import java.io.FileWriter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by zhanghaijun on 15/4/30.
 */
public class enumCreateService {

    private static String beanName = "SmsSearchType";

    /**
     *自动生产枚举类
     */
    public static void autoCreateEnum()throws Exception{
        Map root = getRootMap();
        Configuration cfg = new Configuration();
        cfg.setClassForTemplateLoading(enumCreateService.class, File.separator + "enums");
        Template t = cfg.getTemplate("enum.ftl");
        String filePath = Constant.outPutRootPath+beanName;
        System.out.println(filePath);
        File file = new File(filePath);
        file.createNewFile();
        FileWriter fileWriter = new FileWriter(file);
        Environment ev = t.createProcessingEnvironment(root, fileWriter, null);
        ev.process();
    }

    /**
     * @return
     */
    private static Map getRootMap(){
        return null;
//        List<EnumUnit> list = new ArrayList<EnumUnit>();
//        list.add(new EnumUnit("SMS_LAST_DAY",1, "前一天"));
//        list.add(new EnumUnit("SMS_THIS_WEEK", 2, "本周"));
//        list.add(new EnumUnit("SMS_THIS_MONTH", 3, "本月"));
//        Configuration cfg = new Configuration();
//        cfg.setClassForTemplateLoading(enumCreateService.class, File.separator + "curdTemplates");
//
//        Map root = new HashMap();
//        root.put("className", beanName);
//        root.put("enumlist", list);
//        return root;
    }

    public static void  main(String[] args)throws Exception{
        autoCreateEnum();
    }



}
